<template>
  <base-layout activeIndex="/goods">
    <div slot="content">
      <el-input placeholder="请输入内容" v-model="searchInput" class="input-with-select">
        <span slot="prepend"><i class="el-icon-edit"></i>商品检索</span>
        <el-button slot="append" icon="el-icon-search" @click="doSearch"></el-button>
      </el-input>
      <div style="margin-top:1rem"></div>

      <el-row style="text-align:left">
        <!-- <div style="text-align:left;margin-left:10px">
          
        </div> -->
        <el-col :span="4">
          <el-cascader
            placeholder="选择商品类型"
            :options="goodsTypes"
            v-model="searchType"
            @change="handleChange">
          </el-cascader>
        </el-col>
        <el-col :span="3" :offset="17" style="text-align:right">
          <el-button type="primary" @click="addGoods">添加商品</el-button>
        </el-col>
      </el-row>

      <div style="margin-top:0.5rem"></div>

      <el-table :data="tableData" border stripe highlight-current-row >
        <el-table-column fixed label="商品名称" prop="goodsName" width="150"></el-table-column>
        <el-table-column label="商品类别" prop="typeName"></el-table-column>
        <el-table-column label="商品价格" prop="goodsPrice"></el-table-column>
        <el-table-column label="商品库存" prop="goodsNum"></el-table-column>
        <el-table-column label="商品上架" prop="goodsPrice"></el-table-column>
        <el-table-column label="商品产地" prop="goodsPrice"></el-table-column>
        <el-table-column
        fixed="right"
        label="操作"
        width="100">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="editDetail(scope.$index)">编辑</el-button>
        </template>
      </el-table-column>
      </el-table>

      <div style="margin-top:1rem"></div>
      <el-pagination
        layout="prev, pager, next"
        :total="tableTotal"
        :page-size="20"
        @current-change="pageChange"
        >
      </el-pagination>

      <!-- 编辑器部分 TODO -->

      <el-upload style="display:none"></el-upload>

      <el-dialog title="编辑商品" :visible.sync="editable">
        <el-form :model="newGoods" label-width="80px">
          <el-form-item label="商品名称">
            <el-input v-model="newGoods.goodsName"></el-input>
          </el-form-item>
          <el-form-item label="商品简介">
            <el-input v-model="newGoods.goodsIntroduce"></el-input>
          </el-form-item>
          
          <el-form-item label="商品图片">
            <el-upload action="#" :http-request="handleGoddsImgUpload" list-type="picture-card" :on-preview="handlePictureCardPreview" :on-remove="handleRemove" auto-upload>
                <i class="el-icon-plus"></i>
            </el-upload>
            <el-dialog :visible.sync="goodsAddVisable">
                <img width="100%" :src="dialogImageUrl" alt="">
            </el-dialog>
          </el-form-item>
          <el-form-item>
            
          </el-form-item>
        </el-form>
      </el-dialog>

    </div>
  </base-layout>
</template>

<script>
import BaseLayout from '@/components/BaseLayout'

import api from '../api'
export default {
  components:{
    "base-layout" : BaseLayout
  },
  data(){
    return {
      searchInput : "",
      searchType : "",
      goodsTypes:[],
      editGoods : {},
      editable : false,
      imageList : [],
      goodsAddVisable : false,
      tableData : [
        {
          id:1,
          goodsName:"demo",
          goodsPrice:"demo",
          goodsNum:"demo",
          goodsCanSale:"demo",
          goodsMadeIn:"demo",
          goodsIntroduce:"demo",
          typeId:"demo"
        }
      ],
      dialogImageUrl:"",
      newGoods : {
        goodsName : "",
        goodsPrice:"",
        goodsNum:"",
        goodsCanSale:"",
        goodsMadeIn:"",
        goodsPicUrl:"",
        goodsIntroduce:"",
        goodsDetails: "",
        typeId:""
      },
      tableTotal : 50
    }
  },
  methods:{
    handleGoddsImgUpload(){

    },
    handlePictureCardPreview(file){
      this.dialogImageUrl = file.url;
      this.goodsAddVisable = true;
    },
    handleRemove(file, fileList){

    },
    _queryData(limit,offset,type,keywords){
      api.fetchGoodsInfo(limit,offset,type,keywords)
      .then((res) => {
          
      }).catch((error) => {

      })
    },
    editDetail(index){
      this.editable = true
    },
    doSearch(){
      console.log(this.searchInput)
    },
    handleChange(){

    },
    addGoods(){

    },
    pageChange(currentPage){

    }
  }
}
</script>

<style>

</style>
